import Ember from 'ember';
import {listEqual} from "../utils/mlist-util";

export default Ember.Component.extend({
  init: function() {
    var selected = this.get('selected');
    this.set("__origin", selected.map((it) => {return it;}));
    this._super.apply(this, arguments);
  },
  __origin: [],
  selected: [],
  tobeselect: [],
  // selectedChanged: Ember.observer('selected.[]', function(){
  //   console.log(this.get('selected').length + ":" + this.get('__origin').length);
  // }),
  actions: {
    itemClicked(t, item) {
      var selected = this.get('selected');
      if (t === "selected") {
        selected.removeObject(item);
      } else {
        selected.addObject(item);
      }
      var b = listEqual(selected, this.get('__origin'));
      this.sendAction('action', !b);
    }
  }
});
